package org.popupcommunication.dao.impl;

import java.util.List;
import java.util.Set;

import javax.persistence.Query;

import org.popupcommunication.dao.SujetForumDAO;
import org.popupcommunication.model.Group;
import org.popupcommunication.model.SujetForum;
import org.springframework.stereotype.Repository;

@Repository
public class SujetForumJpa extends GenericRepositoryJpa<SujetForum> implements
		SujetForumDAO {

	@Override
	public List<SujetForum> getListSujets(Group g) {
		Query query = this
				.getEntityManager()
				.createQuery(
						"SELECT s FROM SujetForum s WHERE s.forum=:f ORDER BY s.dateLastResponse DESC");
		query.setParameter("f", g);
		List<SujetForum> lst = (List<SujetForum>) query.getResultList();
		return lst;
	}

	@Override
	public SujetForum findByTitle(String s) {
		Query query = this.getEntityManager().createQuery(
				"SELECT s FROM SujetForum s WHERE s.titre=:title");
		query.setParameter("title", s);
		SujetForum sf = (SujetForum) query.getSingleResult();
		return sf;

	}

}
